package com.zhizuobiao.coura.utils;

import com.zhizuobiao.coura.stockhelper.R;

/**
 * Created by coura on 2016/12/26.
 */

public class WeatherUtil {

    /**
     * 根据加载的天气状况选择相应的天气图片
     * @param weather
     * @return
     */
    public static int getWeatherIcon(String weather) {
        boolean isSun = DateUtil.isSun();
        weather = getWeather(weather,isSun);
        if (weather.equals("晴")){
            return isSun? R.mipmap.w1_s:R.mipmap.w1_m;
        }else if (weather.equals("阴")){
            return R.mipmap.w3;
        }else if (weather.equals("小雨")){
            return R.mipmap.w4;
        }else if (weather.equals("中雨")){
            return R.mipmap.w5_6;
        }else if (weather.equals("大雨")){
            return R.mipmap.w7;
        }else if (weather.equals("阵雨")||weather.indexOf("暴雨")!=-1){
            return R.mipmap.w8;
        }else if (weather.equals("雷阵雨")){
            return R.mipmap.w9;
        }else if (weather.equals("雨夹雪")){
            return R.mipmap.w10;
        }else if (weather.equals("小雪")){
            return R.mipmap.w10;
        }else if (weather.equals("中雪")){
            return R.mipmap.w11_12;
        }else if (weather.equals("大雪")){
            return R.mipmap.w13_14;
        }else if (weather.indexOf("暴雪")!=-1){
            return R.mipmap.w16;
        }else if (weather.equals("冰雹")){
            return R.mipmap.w18;
        }else if (weather.equals("大雾")||weather.indexOf("霾")!=-1){
            return R.mipmap.w30;
        }else if (weather.equals("风")){
            return R.mipmap.w17;
        }else{
            return isSun? R.mipmap.w2_s:R.mipmap.w2_m;
        }
    }

    /**
     * 获取实时温度
     * @param weather
     * @return
     */
    public static String getRealTimeTemperature(String weather){
        //date : 周四 12月22日 (实时：8℃)
        if (weather.indexOf("：")!=-1){
            return weather.split("：")[1].split("\\)")[0];
        }else{
            return "";
        }
    }

    /**
     * 侧滑窗口天气图案
     * @param weather
     * @return
     */
    public static int getWeatherImg(String weather){
        boolean isSun = DateUtil.isSun();
        weather = getWeather(weather,isSun);
        if (weather.indexOf("晴")!=-1){
            return isSun? R.mipmap.banner_fine_day:R.mipmap.banner_fine_night;
        }else if (weather.indexOf("多云")!=-1){
            return isSun? R.mipmap.banner_cloudy_day:R.mipmap.banner_cloudy_night;
        }else if (weather.indexOf("雾")!=-1||weather.indexOf("霾")!=-1){
            return isSun? R.mipmap.banner_fog_day:R.mipmap.banner_fine_night;
        }else if(weather.indexOf("阴")!=-1){
            return R.mipmap.banner_overcast;
        }else if (weather.indexOf("雷")!=-1){
            return R.mipmap.banner_thunder_storm;
        }else if (weather.indexOf("雨")!=-1){
            return R.mipmap.banner_rain;
        }else if (weather.indexOf("雪")!=-1){
            return R.mipmap.banner_day_snow;
        }else if (weather.indexOf("沙尘暴")!=-1){
            return R.mipmap.banner_sand_storm;
        }else {
            return R.mipmap.banner_fine_day;
        }
    }

    public static int getFlag(){
        boolean isSun = DateUtil.isSun();
        return isSun? R.mipmap.w1_s:R.mipmap.w1_m;
    }

    public static String getWeather(String weather,boolean isSun){
        if (weather.indexOf("转") != -1) {
            if (weather.indexOf("到") != -1) {
                return isSun?weather.split("转")[0]:weather.split("转")[1].split("到")[1];
            } else {
                return isSun? weather.split("转")[0]:weather.split("转")[1];
            }
        } else {
            return weather;
        }
    }
}
